package com.cx.abstractFactory.api;


import java.lang.reflect.Proxy;

/**
 * @Author:cxy
 * @Date:2022/3/21 21:48
 */
public class JdkProxyFactory {


    @SuppressWarnings("unchecked")
    public static <T> T getProxy(Class<T> tClass,Class<? extends ICacheAdapter> cacheAdapter){

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Class[] classes = {tClass};

        return (T) Proxy.newProxyInstance(classLoader, classes, (proxy, method, args) -> {
            return cacheAdapter.getInterfaces()[0].getMethod(method.getName(),String.class).invoke(cacheAdapter.newInstance(),args);

//            Object invoke = method.invoke(proxy, args);
//            return invoke;
        });


    }

}
